/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vera.hibernate.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import vera.hibernate.entity.Clients;
import vera.hibernate.util.HibernateUtil;

/**
 *
 * @author vgncr35g
 */
public class ClientsDAO extends EntityDAO{
    public ClientsDAO()
    {
                
    }
    
    public List<Clients> getAllClients()
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getAllClients");
        List<Clients> clients = q.list();
        s.close();
        return clients;
    }
    
    public Clients getClient(int clientCd)
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getClient");
        q.setInteger("clientCd", clientCd);
        Clients client = (Clients) q.uniqueResult();
        s.close();
        return client;
    }
    
    public List<Clients> getAllActiveClients()
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getClientsByStatus");
        q.setString("clientStatCd", "A");
        List<Clients> clients = q.list();
        s.close();
        return clients;
    }
    
    public List<Clients> getAllInactiveClients()
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getClientsByStatus");
        q.setString("clientStatCd", "I");
        List<Clients> clients = q.list();
        s.close();
        return clients;
    }
    
    public void deleteClient(int clientCd)
    {
        deleteEntity(getClient(clientCd));
    }
}
